package elementos;

import mapControl.GraphicsMapControl;

import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.image.Texture.MagnificationFilter;
import com.jme.image.Texture.MinificationFilter;
import com.jme.image.Texture.WrapMode;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.shape.Box;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;

/**
 * Piso del mapa
 * @author Sebastian Giulietti 69032 
 * @author Adrian Sanchez 64251
 *
 */
public class Floor {

	Node nodo;

	/** Constructor de piso
	 * @param mapControl control de mapa
	 */
	public Floor(GraphicsMapControl mapControl) {
		this.nodo = new Node();
		nodo.setName("Floor");
		TextureState ts = mapControl.getDisplay().getRenderer()
				.createTextureState();
		Texture t = TextureManager.loadTexture(getClass().getClassLoader()
				.getResource("data/texturas/floor_texture.jpg"),
				MinificationFilter.NearestNeighborLinearMipMap,
				MagnificationFilter.NearestNeighbor);
		t.setWrap(WrapMode.Repeat);
		ts.setTexture(t);

		Spatial box = new Box("floor_box", new Vector3f((mapControl.getTilesize()
				* mapControl.getWide() / 2), -0.1f, (mapControl.getTilesize()
				* mapControl.getHight() / 2)), mapControl.getTilesize()
				* mapControl.getWide() / 2, 0.1f, mapControl.getTilesize()
				* mapControl.getHight() / 2);

		box.setModelBound(new BoundingBox());
		box.updateModelBound();

		box.setRenderState(ts);
		nodo.attachChild(box);

		mapControl.getRootNode().attachChild(nodo);
		mapControl.getRootNode().updateGeometricState(0, true);
	}

}
